﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Group_Mail.Controls
{
    public class CheckBoxToolStripItem : ToolStripControlHost
    {
        private readonly CheckBox checkbox = new CheckBox();
        private readonly FlowLayoutPanel controlPanel;

        public CheckBoxToolStripItem()
            : base(new FlowLayoutPanel())
        {
            controlPanel = (FlowLayoutPanel) Control;
            controlPanel.BackColor = Color.Transparent;
            checkbox.AutoSize = true;
            checkbox.CheckedChanged += checkbox_CheckedChanged;
            controlPanel.Controls.Add(checkbox);
        }

        public override string Text
        {
            get { return checkbox.Text; }
            set { checkbox.Text = value; }
        }

        public bool Checked
        {
            get { return checkbox.Checked; }
            set { checkbox.Checked = value; }
        }

        public event EventHandler CheckedChanged;

        private void checkbox_CheckedChanged(object sender, EventArgs e)
        {
            if (CheckedChanged != null)
            {
                CheckedChanged(this, e);
            }
        }
    }
}